import request from '@/utils/request'

/**
 * 获取试题列表
 */
export const getExamQuestions = async (params) => {
  return request('/admin/questions?include=user,category,questions', { params })
}

/**
 * 获取试题的分类
 */
export const getExamCategory = async () => {
  return request('/admin/categories?category_group=text-bank')
}

/**
 *添加题目
 */
export const addExamQuestion = async (data) => {
  const options = {
    data
  }
  return request.post('/admin/questions', options)
}

/**
 * 执行修改题目
 */
export const editExamQuestion = async (data) => {
  return request.put(`/admin/questions/${data.id}`, { data })
}

/**
 * 删除题目
 */
export const deleteQuestion = async (qid) => {
  return request.delete(`/admin/questions/${qid}`)
}

/**
 * 题目详情
 */
export const getExamQuestionDetail = async (eqid, params) => {
  return request(`/admin/questions/${eqid}?include=user,category,questions`, {
    params
  })
}

/**
 * 修改题目状态
 */
export const changeStatusQuestion = async (data)=> {
  return request('/admin/questions/status', {
    method: 'PATCH',
    data
  })
}

/**
 * 下载Excel模板
 * @returns {Promise<any>}
 */
export const excelModelQuestion = async () => {
  return request('/admin/questions/excel',{
    headers: {
      'biz-source-param': 'BLG'
    },
    responseType: 'blob',
  })
}

/**
 * 批量导入
 * @param params
 * @returns {Promise<*>}
 */
export const excelQuestion = async (params) => {
  return request('/admin/questions/export', {
    headers: {
      'biz-source-param': 'BLG'
    },
    responseType: 'blob',
    params
  })
}

/**
 * 批量导入
 * @param file
 * @returns {Promise<any>}
 */
export const importQuestion = async (file) => {
  return request('/admin/questions/import', {
    method: 'POST',
    body: file
  })
}

